<%@page import="com.bill.common.utils.TranType"%>
<%@page import="com.bill.common.system.dto.SingleGroupReportStatDTO"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.bill.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.bill.common.system.service.ITransactionRecordService"%>
<%@page import="com.bill.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/dynamicAward.jsp");
	return; 
}

ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
TransactionRecordDTO trDTO = new TransactionRecordDTO();
trDTO.setLoginName((String)session.getAttribute("loginName"));
int pages = 1;
String sidx = "recordId";
String sord="desc";

Object param1 = request.getParameter("trDTO.transactionType");

if(param1!=null 
&& param1!="" 
&& !"null".equals(param1)){
	trDTO.setTransactionType(request.getParameter("trDTO.transactionType"));
	pages=1;
}

if(request.getParameter("pages")!=null && request.getParameter("pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;

//搜索类型：
String[] transactionTypes = TranType.Dynamics;
trDTO.setStart( start );
trDTO.setLimit( rows );
trDTO.setTransactionTypes(transactionTypes);
trDTO.setSearchType("Dynamic");

trDTO.setDtype("Dynamic");
PageDTO pageDTO = transactionRecordService.findTransactionRecordPager(trDTO, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);

//统计：
Double income = 0D;
TransactionRecordDTO trDto1 = new TransactionRecordDTO();
trDto1.setInOrExp("income");
trDto1.setDtype("Dynamic");
trDto1.setTransactionTypes(transactionTypes);
trDto1.setLoginName((String)session.getAttribute("loginName"));
List<SingleGroupReportStatDTO> sgrs = transactionRecordService.statAccount(trDto1);
for(SingleGroupReportStatDTO sgr : sgrs){
	if(sgr.getAggField()!=null){
		income = income+sgr.getAggField();
	}
}
request.setAttribute("income",income);
request.setAttribute("transactionTypes", transactionTypes);
%>
<fmt:setLocale value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
	<fmt:setBundle basename="i18n.itilbase"/>
	<c:set var="lang" value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" >
<title><fmt:message key="i18n.dyMoneyDetail"/>-<fmt:message key="i18n.title"/> </title>
<link rel="shortcut icon" href="../index/favicon.png" />
<link rel="stylesheet" type="text/css" href="css/style1.css">
<script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>
<style type="text/css">
</style>
</head>
<body>
	<div class="top2">
		<a href="index.jsp" class="top2L" ><fmt:message key="i18n.moneyManage"/> ></a>
		<a href="index.jsp" class="top2L" ><fmt:message key="i18n.jiangjinMX"/> ></a>
	</div>
	<div class="cont">
		<div class="tx_Top">
			<p><fmt:message key="i18n.totalincome"/>:<fmt:formatNumber value="${income}" pattern="#0.0000"/> </p>
		</div>
		<form id="bonusSeachForm" action="dynamicAward.jsp" method="post">
			<input name="sidx" value="recordId" type="hidden" >
			<input name="sord" value="desc" type="hidden" >
			<input name="trDTO.searchType" value="bonus" type="hidden" >
			<input name="trDTO.loginName" value="${session.loginName }" type="hidden" >
		<div class="tx_cont">
			<div class="tx_contBox ">
				<p class="tx_contBoxL"><fmt:message key="i18n.type"/>：</p>
				<div class="tx_contBoxR">
					<div class="tx_contBoxR2"><div class="tx_contBoxRS"></div>
						<select  id="dtype" name="trDTO.transactionType" class="tx_contBoxR2_1">
							<option value="">--<fmt:message key="i18n.pelaseSelect"/>--</option>
							<c:forEach items="${transactionTypes}" var="tts">
								<option value="${tts}"><fmt:message key="${tts}" /></option>
							</c:forEach>
						</select>
					</div>
				</div>
			</div>
			<div class="tx_contBox ">
				<p class="tx_contBoxL"><fmt:message key="i18n.jiesuanData"/>：</p>
				<div class="tx_contBoxR" style="width:auto;">
					<input class="tx_contBoxR3" type="text" name="trDTO.startTime" placeholder="<fmt:message key="i18n.inputStartTime"/>" >
				</div>
			</div>
			<div class="tx_contBox ">
				<p class="tx_contBoxL"><fmt:message key="i18n.jiesuanData"/>：</p>
				<div class="tx_contBoxR" style="width:auto;">
					<input class="tx_contBoxR3" type="text" name="trDTO.endTime" placeholder="<fmt:message key="i18n.inputEndTime"/>" >
				</div>
			</div>
			<div class="tx_contBox ">
				<p class="tx_contBoxL">&nbsp;</p>
				<div class="tx_contBoxR">
					<c:if test="${not empty session.activationTime}">
						<input class="tx_contBoxRAn" type="submit" value="<fmt:message key="i18n.serach"/>">
					</c:if>
				</div>
			</div>
		</div>
		</form>
		<div>
			<table class="txList" width="100%" cellspacing="0" cellpadding="0">
				<thead>
				<tr>
					<th><fmt:message key="i18n.type"/></th>
    				<th><fmt:message key="i18n.jiaoyiUser"/></th>
    				<th><fmt:message key="i18n.income"/></th>
    				<%--  <th><fmt:message key="i18n.transferredBonus"/></th>
    				
    				<th><fmt:message key="i18n.zhichu"/></th>
    				<th><fmt:message key="i18n.balance"/></th>--%>
    				<th><fmt:message key="i18n.operationTime"/></th>
    				<th><fmt:message key="i18n.remark"/></th>
				</tr>
				</thead>
				<tbody>
       			<c:forEach items="${pageDTO.data}" var="data">
       				<tr>
       					<td align="left">
       						<fmt:message key="${data.transactionType}"/>
       					</td>
       					<td>${data.transactionObject}</td>
       					<td><fmt:formatNumber value="${data.income}" pattern="#0.0000"/></td>
       					<%-- <td><fmt:formatNumber value="${data.bugOutSumOfMoney}" pattern="#0.0000"/></td>
       					 
       					<td>${data.expenditure}</td>
       					<td><fmt:formatNumber value="${data.balance}" pattern="#0.0000"/></td>--%>
       					<td><fmt:formatDate value="${data.optDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
       					<td>${data.remark}</td>
       				</tr>
       			</c:forEach>
       			<c:if test="${empty pageDTO.data}">
       				<tr>
       					<td colspan="7" align="center"><fmt:message key="i18n.noData"/></td>
       				</tr>
       			</c:if>
       		</tbody>
			</table>
		</div>
		
	</div>
	<!-- 分页 start -->
	<div class="page">
		<div id="tr_recommendGrid_pager" class="page">
			<li><a href="dynamicAward.jsp?pages=1&trDTO.transactionType=<%=request.getParameter("trDTO.transactionType") %>"><fmt:message key="i18n.firstPage"/></a>
				<c:if test="${pageDTO.page!=1}">
					<a href="dynamicAward.jsp?pages=${pageDTO.page-1}&trDTO.transactionType=<%=request.getParameter("trDTO.transactionType") %>"><fmt:message key="i18n.upPage"/></a>
				</c:if>
				<a>${pageDTO.page}/${pageDTO.total}</a>
				<c:if test="${pageDTO.page+1<=pageDTO.total}">
					<a href="dynamicAward.jsp?pages=${pageDTO.page+1}&trDTO.transactionType=<%=request.getParameter("trDTO.transactionType") %>"><fmt:message key="i18n.nextPage"/></a>
				</c:if>
				<a href="dynamicAward.jsp?pages=${pageDTO.total}&trDTO.transactionType=<%=request.getParameter("trDTO.transactionType") %>"><fmt:message key="i18n.endPage"/></a>
				<a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a></li>
		</div>
	</div>
	<!-- 分页 end  -->
<script>
$(function(){
	var _result = '${param.result}';
	if(_result=='TixiangSumGeBalance'){
		alert('The withdrawal amount is greater than can(提现金额大于可提现金额)!');
		window.location.href="cashBusiness.jsp";
	}else if(_result=='ApplyLoginNameNotExist'){
		alert('Apply for membership does not exist(申请的会员不存在)!');
		window.location.href="cashBusiness.jsp";
	}else if(_result=='Success'){
		alert('Successful applicants will be accepted as soon as possible, the financial(申请成功，财务会尽快受理)!');
		window.location.href="cashBusiness.jsp";
	}
})

function changeRmb(){
	//$('#changeRmb').text($('#extractMoney').val()*4);
}


function checkform(){
	//alert('此期间与英国本部进行财务对接，不允许提现，详情请查看公告!');
	//return false;
	/* if($('#cashBusiness_validCode').val()==null || $('#cashBusiness_validCode').val()==''){
		alert('Please input the valid code(请输入验证码)!');
		return false;
	}
	 */
	var extractMoney = $('#extractMoney').val();
	if(extractMoney==null || extractMoney==''){
		alert('Please input the withdrawal(请输入提现金额)!');
		return false;
	}
	if(extractMoney % 100 != 0){
		alert('Please enter 10 times the amount(请输入100的倍数提现金额)!');
		return false;
	}
	if(extractMoney < 100){
		alert('Minimum withdrawals over 100(最低提现100以上)!');
		return false;
	}
	
	if($('#passwordAnswer').val()==''){
		alert('Secret security answer can not be empty(密保答案不能为空)!');
		$('#passwordAnswer').focus();
		return false;
	}
	if($('#dtype').val()=='Dynamic' &&  parseFloat($('#cashbussiness_balance1').val())<parseFloat($('#extractMoney').val())){
		 alert('Extraction of failure, can be extracted in excess of the amount(提取失败,可提取金额超出)!');
		 return false;
	}
	if($('#dtype').val()=='Static' &&  parseFloat($('#cashbussiness_balance2').val())<parseFloat($('#extractMoney').val())){
		 alert('Extraction of failure, can be extracted in excess of the amount(提取失败,可提取金额超出)!');
		 return false;
	}
	
	
	/* $.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=提现&dto.activationCode='+$('#cashBusiness_validCode').val(),function(res){
		 if(!res){
			 alert('E-mail verification code is not correct(邮箱验证码不正确)!');
			 return false;
		 }else{
			 $('#cashBusinessForm').submit();
		 }
	}); */
}

</script>


</body>
</html>